//
// Created by 86131 on 2023/12/20.
//
#include "bits/stdc++.h"
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    int a[n+1][n+1];
    int v[n+1];
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            a[i][j]=0;
        }
    }
    for(int i=1;i<=m;i++){
        int c,b;
        cin>>c>>b;
        a[c][b]=1;
        a[b][c]=1;
    }
    int r;
    cin>>r;
    for(int i=0;i<r;i++){
        for(int o=1;o<=n;o++){
            v[o]=0;
        }
        int flag=1;
        int t;
        cin>>t;
        int u;
        for(int j=0;j<t;j++){
            if(!j){cin>>u;
                continue;}
            int p;
            cin>>p;
            if(a[u][p]){
                if(!v[p]){
                    v[p]=1;
                }else{
                    flag=0;
                }
            }
            u=p;
        }
        for(int o=1;o<=n;o++){
            if(!v[o]){
            flag=0;
                break;
            }
        }
        if(flag){
            cout<<"YES"<<endl;
        }else{cout<<"NO"<<endl;}
    }

}